package com.macro.mall.controller;

import com.macro.mall.common.annotation.AccessLimit;
import com.macro.mall.common.api.CommonPage;
import com.macro.mall.common.api.CommonResult;
import com.macro.mall.dto.SmsMessageHistoryQuery;
import com.macro.mall.model.SmsMessageHistory;
import com.macro.mall.service.SmsMessageHistoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 短信历史记录查询Controller
 *
 * @author 郎
 */
@Controller
@Api(tags = "SmsMessageController")
@Tag(name = "SmsMessageController", description = "短信历史记录查询")
@RequestMapping("/messageHistory")
@AllArgsConstructor
public class SmsMessageHistoryController {

    private final SmsMessageHistoryService smsMessageHistoryService;

    @AccessLimit
    @ApiOperation("分页查询短信历史记录")
    @RequestMapping(value = "/list", method = RequestMethod.GET)
    @ResponseBody
    public CommonResult<CommonPage<SmsMessageHistory>> list(SmsMessageHistoryQuery query, @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                                                            @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize) {
        List<SmsMessageHistory> list = smsMessageHistoryService.list(query, pageNum, pageSize);
        return CommonResult.success(CommonPage.restPage(list));
    }

    @AccessLimit
    @ApiOperation("根据ID获取短信历史记录详情")
    @RequestMapping(value = "/detail/{id}", method = RequestMethod.GET)
    @ResponseBody
    public CommonResult<Object> detail(@PathVariable("id") Long id) {
        return CommonResult.success(smsMessageHistoryService.detail(id));
    }
}
